/**
 * instantiate a modal popup dialog with form included
 * 
 * @param string formcontainerid
 * @param string xhr target, e.g. ?test.php
 * @param string width of container, default: 200px
 * @param bool keep dialog in center, default = true
 * @param array btn definiton 0 = okay btn text, 1 = cancel btn text
 */
function phpmyPopUpModalForm (formcontainerid, posttarget, vwidth, vfixedcenter, btn) {
    if (!vwidth)
        vwidth = '200px';
    if (!vfixedcenter)
        vfixedcenter = true;    
    if (btn) {
        if (!btn[0]) 
            btnokay = 'okay';
        else 
            btnokay = btn[0];
        if (!btn[1]) 
            btncancel = 'cancel';
        else 
            btncancel = btn[1];
    } else {
        btncancel = 'cancel';
        btnokay = 'okay';
    }                  
    // Define various event handlers for Dialog
    var handleSubmit = function() {
        // send form                            
        // get form id within container                
        var myEls = YDom.getElementsBy(function(el){return true;},'form', formcontainerid);
        myEls = YDom.get(myEls[0]);        
        _ajaxSendPostForm (posttarget, myEls.getAttribute("id"));            
    };
    var handleCancel = function() {
        this.cancel();
    };
    // Instantiate the Dialog
    var anntype = new YAHOO.widget.Dialog(formcontainerid,
                            { width : vwidth,
                              fixedcenter : vfixedcenter,
                              visible : false,
                              modal: true,
                              zindex: 1000,
                              postmethod: "form",
                              constraintoviewport : true,
                              buttons : [{ text:btnokay, handler:handleSubmit, isDefault:true },
                                         { text:btncancel, handler:handleCancel } ]
                            });
    var kl = new YAHOO.util.KeyListener(formcontainerid, { keys:13 },
                                              { fn:handleSubmit,
                                                scope:anntype,
                                                correctScope:true }
                                                );
    anntype.cfg.queueProperty("keylisteners", kl);
    anntype.render(document.body);    
    return anntype;
}
/**
 * init modal content box
 * @param string header
 * @param string body
 * @param bool init visible or not
 * @return object instance
 */
function phpmyContentModal (header, body, visible)
{
 var mask =  new YAHOO.widget.Panel("wait",
         { width:"240px",
            fixedcenter:true,
            close:false,
            draggable:false,
            zindex:1002,
            modal:true,
            visible:(visible ? true : false )}
 );
 mask.setHeader(header);
 mask.setBody(body);
 mask.render(document.body);
 return mask;
}
 /**
  * instantiate a simple modal popup dialog with form included and one button for submit
  * 
  * @param string formcontainerid
  * @param string xhr target, e.g. ?test.php
  * @param string width of container, default: 200px
  * @param bool keep dialog in center, default = true
  * @param array btn definiton
  */
 function phpmyPopUpSimpleModalForm (formcontainerid, posttarget, vwidth, vfixedcenter, btn) {
     if (!vwidth)
         vwidth = '200px';
     if (!vfixedcenter)
         vfixedcenter = true;    
     if (btn) {
         btnokay = btn;
     } else {         
         btnokay = 'okay';
     }                  
     // Define various event handlers for Dialog
     var handleSubmit = function() {
         // send form                            
         // get form id within container                
         var myEls = YDom.getElementsBy(function(el){return true;},'form', formcontainerid);
         myEls = YDom.get(myEls[0]);        
         _ajaxSendPostForm (posttarget, myEls.getAttribute("id"));            
     };
     var handleCancel = function() {
         this.cancel();
     };
     // Instantiate the Dialog
     var anntype = new YAHOO.widget.Dialog(formcontainerid,
                             { width : vwidth,
                               fixedcenter : vfixedcenter,
                               visible : false,
                               modal: true,
                               zindex: 1000,
                               postmethod: "form",
                               close: false,
                               draggable: false,
                               constraintoviewport : true,
                               buttons : [{ text:btnokay, handler:handleSubmit, isDefault:true }]
                             });
     var kl = new YAHOO.util.KeyListener(formcontainerid, { keys:13 },
                                               { fn:handleSubmit,
                                                 scope:anntype,
                                                 correctScope:true }
                                                 );
     anntype.cfg.queueProperty("keylisteners", kl);
     anntype.render(document.body);    
     return anntype;
 }